package cn.hd.userService.controller.role;

import cn.hd.commonService.vo.Result;
import cn.hd.commonService.annotations.LogAnnotation;
import cn.hd.commonService.enums.MethodType;
import cn.hd.userService.service.role.SysRoleFuncService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/roleFunction")
@Api(tags = "角色和功能相关操作")
public class RoleFunctionController {

    @Autowired
    private SysRoleFuncService roleFuncService;

    @PostMapping("/saveRelation")
    @ApiOperation(value = "角色授权")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleIds",value = "角色id"),
            @ApiImplicitParam(name = "functionIds",value = "功能id")
    })
    @LogAnnotation(methodName = "角色授权",methodDesc = "保存角色和功能的关联关系",methodType = MethodType.POST_TYPE)
    public Result saveRelation(String roleIds, String functionIds){
        Assert.hasText(roleIds,"角色id不能为空");
//        Assert.hasText(functionIds,"功能id不能为空");
        roleFuncService.saveRelation(roleIds,functionIds);
        return Result.success("授权成功");
    }
}
